package com.agileboot.domain.performance.submission.model;

import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode;
import com.agileboot.domain.performance.submission.db.SubmissionEntity;
import com.agileboot.domain.performance.submission.db.SubmissionService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 绩效上报项模型工厂
 */
@Component
@RequiredArgsConstructor
public class SubmissionModelFactory {

    private final SubmissionService submissionService;

    public SubmissionModel loadById(Long id) {
        SubmissionEntity byId = submissionService.getById(id);
        if (byId == null) {
            throw new ApiException(ErrorCode.Business.COMMON_OBJECT_NOT_FOUND, id, "绩效上报项");
        }
        return new SubmissionModel(byId, submissionService);
    }

    public SubmissionModel create() {
        return new SubmissionModel(submissionService);
    }

}
